package ru.averta.notes.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import ru.averta.notes.domain.abstr.BusinessObject;
import ru.averta.notes.domain.abstr.UserableObject;
import ru.averta.notes.domain.flags.ITagable;

@Entity
@Table(name = "Notes")
public class Note extends UserableObject implements BusinessObject, ITagable {

	@Column(name = "USER_NAME")
	private String userName;

	@Column(name = "TITLE")
	private String title;

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="FOLDER_ID")
	private Folder folder;

	/*
	 * GET / SET
	 */

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setFolder(Folder folder) {
			if (this.folder != null) this.folder.removeNote(this);
			if (folder != null) folder.addNote(this);
			this.folder = folder;
	}

	protected void setFolder0(Folder folder) {
		this.folder = folder;
	}

	public Folder getFolder() {
		return folder;
	}

}
